package com.enation.app.web.core.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * 
 * @function 计算访问数量
 * @author 闯哥
 * @time 2016年10月19日 下午8:35:48
 */
public class MySessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent event) {

		ServletContext context = event.getSession().getServletContext();
		Integer num = (Integer) context.getAttribute("num");
		if (num == null) { 
			num = 1;
			context.setAttribute("num", num);
		} else {
			num = num + 1;
			context.setAttribute("num", num);
		}

	}

	@Override
	public void sessionDestroyed(HttpSessionEvent arg0) {
		// TODO Auto-generated method stub

	}

}
